#include "sqlquery.h"
#include "ui_sqlquery.h"

sqlQuery::sqlQuery(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::sqlQuery)
{
    ui->setupUi(this);
    setTableSty();
}

sqlQuery::~sqlQuery()
{
    delete ui;
}

//输入信息查询对应的数据
void sqlQuery::on_cQuery_clicked()
{

   QString columnName = ui->selectBoxInfo->currentText();
   QString serachKey = ui->iInfoEdit->text();
//    QString str = QString("SELECT * FROM `表名` WHERE "选取列名" LIKE '%筛选信息关键字%'").arg().arg().arg();
    QString selectInfo = QString("SELECT * FROM %1 WHERE %2 LIKE '%%3%'")
            .arg(tableName).arg(columnName).arg(serachKey);
    qDebug()<<selectInfo;
    model.setQuery(selectInfo);
    ui->cQueryView->setModel(&model);
//    ui->sqlite_View->setModel(&model);

//    qDebug() << "columnName:" + columnName;
//    qDebug() << "serachKey:" + serachKey;
}

void sqlQuery::setTableSty()
{
//    让sql数据填满容器
    ui->cQueryView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    ui->cQueryView->verticalHeader()->hide();//    隐藏第一列
    ui->cQueryView->setAlternatingRowColors(true);//使表格颜色交错功能为真
    ui->cQueryView->horizontalHeader()->setStyleSheet("QHeaderView::section{background:rgb(249, 247, 232);color: #62bfad;}");//设置表头背景和字体颜色
}
